In [3]:
import matplotlib.pyplot as plt
from PIL import ImageFilter, Image, ImageEnhance
import numpy as np
In [73]:
### Применить 5 фильтров к своей фотке

path = 'photo.png'
img = plt.imread(path)

# great summary of Colormaps in Matplotlib can be found here
# https://matplotlib.org/stable/tutorials/colors/colormaps.html
In [30]:
print(img.shape)
(768, 1366, 3)
In [31]:
plt.imshow(img)
plt.axis('off')
plt.show()
In [39]:
## standard way

# 1st filter
plt.imshow(img.mean(2), cmap='magma')
plt.axis('off')
plt.show()
In [33]:
# 2nd filter
plt.imshow(img.mean(2), cmap='jet')
plt.axis('off')
plt.show()
In [48]:
# 3rd filter
plt.imshow(img.mean(2), cmap='seismic')
plt.axis('off')
plt.show()
In [38]:
# 4th filter
plt.imshow(img.mean(2), cmap='bone')
plt.axis('off')
plt.show()
In [52]:
# 5th filter
plt.imshow(img.mean(2), cmap='Set2')
plt.axis('off')
plt.show()
In [74]:
## PIL way

img = Image.open(path)
img
Out[74]:
In [75]:
# 1st filter
img.convert('L')
Out[75]:
In [59]:
# 2nd filter
img.filter(ImageFilter.SMOOTH)
Out[59]:
In [68]:
# 3rd filter
img.filter(ImageFilter.GaussianBlur(radius=5))
Out[68]:
In [61]:
# 4th filter
img.filter(ImageFilter.FIND_EDGES)
Out[61]:
In [63]:
# 5th filter
enh = ImageEnhance.Sharpness(img)
enh.enhance(20.0)
Out[63]:
In [81]:
### Сделать программу для поиска кружочков в изображении

import matplotlib.pyplot as plt
from PIL import ImageFilter, Image, ImageEnhance
import cv2
import numpy as np
In [83]:
img = cv2.imread('puzyrki.jpg')
imgc = img.copy()
#kernel = np.ones((10,10),np.uint8)
#blur = cv2.morphologyEx(imgc, cv2.MORPH_CLOSE, kernel)
gray_output = cv2.cvtColor(imgc, cv2.COLOR_BGR2GRAY)

circles = cv2.HoughCircles(gray_output, 
                           cv2.HOUGH_GRADIENT, 
                           dp=1,
                           param1 = 90,
                           param2 = 80,
                           minDist= 100, 
                           minRadius=10, 
                           maxRadius=500)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)

plt.imshow(img)
plt.axis('off')
plt.show()